import { UserData } from "./UserData";

// 课程
export interface Course {
    courseId: number;
    courseName: string;
    courseDifficultyId: number;
    courseCover: string;
    coverPath: string;
    courseDescription: string;
    createBy: number;
    createDate: string;
}

// 课程类型
export interface CourseType {
    typeId: number;
    typeName: string;
    typeDesc?: string;
    createDate?: string;
}

// 课程标签
export interface CourseLabel {
    labelId: number;
    labelName: string;
    labelDesc?: string;
    createDate?: string;
}

// 课程难度
export interface CourseDifficulty {
    difficultyId: number;
    difficultyName: string;
    difficultyDesc?: string;
    createDate?: string;
}

// 章节
export interface Chapter {
	chapterId: number,
	courseId: number,
	chapterName: string,
	displayOrder: number,
	createBy: number,
	createDate: string,
	updateBy: number,
	updateDate: string
}

// 课时
export interface Lessons {
	lessonsId: number,
	chapterId: number,
	lessonName: string,
	displayOrder: number,
	createBy: number,
	createDate: string,
	updateBy: number,
	updateDate: string
}

// 课时资源
export interface LessonsResource {
	resourceId: number,
	lessonsId: number,
	resourceType: string,
	resourceName: string,
	displayOrder: number,
	progress?: number,
	file?: File,
	resourceLink: number,
	resourceUrlName: string,
	resourceUrl: string,
	resourceSize: number,
	durationSeconds: number,
	createDate: string,
	updateDate: string
}

// 问题
export interface Question {
	recId: number,
	exercisesId: number,
	questionTitle: string,
	questionType: string,
	score: number,
	displayOrder: number,
	answerOptions: string,
	checkbox?: boolean,
	answer: string,
	answerHtml: string
	analysis: string,
    userAnswerHtml: string,
	userAnswerText: string
}

// 题目
export interface Exercises {
	exercisesId?: number,
	chapterId?: number,
	courseId: number,
	title: string,
	questionStem?: string,
	exerciseType: string,
	difficulty: number,
	difficultyText?: string,
	topicStatus?: string,
	accuracy?: number,
	challengeNum?: number,
	forPractice?: number,
	forTest?: number,
	dataType: string,
	createBy?: number,
	createDate?: string,
	updateBy?: number,
	updateDate?: string,
	isPublic?: number,
	eleRemark?: string,
	questions?: Question[],
	knowledges?: KnowledgePoint[],
	chapterInfo?: Chapter
}

// 知识点
export interface KnowledgePoint {
	recordId: number,
	courseId: number,
	cameraId: number,
	quoteRecordId: number,
	quoteTime: string,
	recordType: string,
	recordUrl: string,
	knowledgeContent: string,
	fileSize: string,
	isPublic: boolean,
	uploadBy: number,
	uploadTime: string,
	recordRemark: string
}

// 课程教师
export interface CourseTeacher {
    teacher: UserData;
    studentCount: number;
    courseCount: number;
    courseList: number[];
}

// 课程统计数据
export interface CourseFigures {
    courseId: number;
    courseName: string;
    courseDifficultyId: number;
    studentCount: number;
    commentCount: number;
    avgScore: number;
    updateTime: string;
}

// 课程详情
export interface CourseDetail {
    courseInfo: Course;
    courseFigures: CourseFigures;
    courseType: CourseType[];
    courseLabel: CourseLabel[];
    courseDifficulty: CourseDifficulty;
    courseTeacher: CourseTeacher;
    collect:  boolean;
    recommendCourse: number[];
}

// 课程资源文件
export interface CourseResourceFile {
    fileId?: number;
    resourceId?: number;
    fileName: string;
    contentType?: string;
    fileSize?: number;
    filePath?: string;
    createDate?: string;
	selected?: boolean;
	progress?: number;
}

// 课程资源列表
export interface CourseResource {
    courseId: number;
    resourceId: number;
    uploadUser?: UserData;
    resourceName: string;
    fileCount?: number;
    downloadCount?: number;
    updateDate?: string;
	fileList?: CourseResourceFile[];
}

// 课程评论
export interface CourseComment {
    commentId: number;
    courseId: number;
    userId?: number;
	parentId: number;
	userInfo: UserData;
	content: string;
	score: number;
	createDate: string;
	children: CourseComment[];
}

// 课程成员分组
export interface CusStudyGroup {
	groupId: number;
	courseId: number;
	groupName: string;
	createor?: string;
	createTime?: string;
	updateTime?: string;
	updateor?: string;
	userRegistCus?: UserRegistCus[];
}

// 课程成员
export interface UserRegistCus {
	courseId: number;
	userId: number;
	groupId: number;
	userNickName: string;
	registTime: string;
	permission: number;
	userInfo: UserData;
}

// 作业题目
export interface HomeworkExercises {
	homeworkId?: number;
	exercisesId: number;
	exerciseScore: number;
	exerciseInfo: Exercises;
}

// 作业
export interface Homework {
	homeworkId?: number;
	targetId: number;
	homeworkName: string;
	homeworkType: string;
	fullMark: number;
	updateDate?: string;
	exerciseCount: number;
	exercises: HomeworkExercises[];
}

// 作业提交记录
export interface UreceiveHwrec {
	userId: number;
	publishId: number;
	receiveTime: string;
	homeworkComment: string;
	markMan: string;
	markTime: string;
	score: number;
}

// 作业成员
export interface HomeworkMember {
	courseMember: UserRegistCus;
	ureceiveHwrec: UreceiveHwrec;
}

// 发布作业
export interface PublishHomework {
	publishId: number;
	targetId: number;
	homeworkId: number;
	publishType: string;
	startTime: string;
	endTime: string;
	canSubmitOverTime: boolean;
	exerciseShuffle: boolean;
	optionShuffle: boolean;
	publishDate: string;
	status?: number;
	score?: number;
	homeworkMembers: HomeworkMember[];
	cusStudyGroup: CusStudyGroup;
	homeworkInfo?: Homework;
	submitCount?: number;
	unSubmitCount?: number;
	pendingReviewCount?: number;
}

// Homework 类型守卫
export const isHomework = (item: any): item is Homework => {
    return !!item && 
        'homeworkId' in item &&
        'targetId' in item &&
        'homeworkName' in item &&
        'homeworkType' in item &&
        'fullMark' in item &&
        'updateDate' in item &&
        'exerciseCount' in item &&
        'exercises' in item;
}

// 转换函数
export const convertHomeworkToPublish = (
    homework: Homework,
    publishType: string = 'Test', 
    startTime: string = '',
    endTime: string = '',
    canSubmitOverTime: boolean = false, exerciseShuffle: boolean = false,
    optionShuffle: boolean = false,
): PublishHomework => {
    return {
        // 生成必要发布信息
        publishId: homework.homeworkId, // 临时ID
        homeworkId: homework.homeworkId,
        publishType: publishType,
        startTime: startTime,
        endTime: endTime,
        canSubmitOverTime: canSubmitOverTime,
        exerciseShuffle: exerciseShuffle,
        optionShuffle: optionShuffle,
        publishDate: homework?.updateDate,
		status: -1,
		score: 0,
        // 保留原始作业数据
        homeworkInfo: homework
    } as PublishHomework
}

export interface CourseResponse {
    data: Course[];
    total: number;
} 